#include "../main.h"

#define PATH_FIFO "/home/yujiu/fifo"

int main()
{
    int ret=0;
    ret=access(PATH_FIFO,F_OK);
    if(ret==-1){
        perror(PATH_FIFO);
        exit(1);
    }
    int fd=open(PATH_FIFO,O_WRONLY);
    if(-1==fd){
        perror("open");
        exit(EXIT_FAILURE);
    }
    char buf[128];
    ssize_t byte;
    while(1){
        memset(buf,0,sizeof(buf));
        printf("input:");
        fflush(stdout);
        fgets(buf,sizeof(buf),stdin);
        buf[strlen(buf)-1]='\0';
        byte=write(fd,buf,strlen(buf));
        if(-1==byte){
            perror("write");
            close(ret);
            exit(EXIT_FAILURE);
        }
        if(strncmp("exit",buf,4)==0){
            break;
        }
    }
    close(fd);
    return 0;
}

